from django.shortcuts import render
from django.http import HttpResponse
from django.shortcuts import redirect,render
from django.conf import settings
import random
from utils.tencent import *

# Create your views here.
def send_sms(request):
    '''
    发送短信
     单条发送短信
    :param phone_num: 手机号
    :param template_id: 腾讯云短信模板ID
    :param template_param_list: 短信模板所需参数列表，例如:【验证码：{1}，描述：{2}】，则传递参数 [888,666]按顺序去格式化模板
    :return:
    '''
    tel = request.GET.get('tpl')
    template_id = settings.TENCENT_SMS_TEMPLATE.get('tpl')
    if not template_id:
        return HttpResponse('模板不存在')
    code = random.randrange(1000,9999)
    res = send_sms_single('电话号码', template_id, [code,])
    if res['result'] == 0:
        return HttpResponse('成功')
    else:
        return HttpResponse(res['errmsg'])


from django import forms
from . import models

class RegisterModelForm(forms.ModelForm):
    class Meta:
        models = models.UserInfo
        fields = "__all__"


def register(request):
    form = RegisterModelForm()
    return render(request,'register.html', {'form',form})